home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BKISSSRC.ZIP / CREDITS / MODEX.INC < prev    next >
Encoding:
Text File  |  1994-02-07  |  21.7 KB  |  743 lines

  1. ;this was originally by Draeden of VLA, but I have cleaned it up a little
  2. ;bit (ie: making all symbol references use same case, removing redundant
  3. ;macros/equates, etc.)  I have also added the 320x80x256 mode
  4.  
  5. ;Note:  This was originally from the Faker demo as was used as an 80x80
  6. ;mode.  To use it in this fashion (or any other mode, for that matter),
  7. ;enable writes to all planes and then treat it as a standard chained video
  8. ;mode (except with 320/4 or 80 bytes as the width).  This makes 4 pixels
  9. ;get treated as one entity
  10. LABEL X320Y80 word
  11.     db      00      ; dot clock
  12.     db      03      ; Number of CRTC Registers to update
  13.     dw      00409h  ; cell height
  14.     dw      00014h  ; turn off dword mode
  15.     dw      0e317h  ; turn on byte mode
  16.     dw      320     ; width
  17.     dw      80      ; height
  18.  
  19. LABEL X320Y200 word
  20.     db      00      ; 0e3h    ; dot clock
  21.     db      02      ; Number of CRTC Registers to update
  22.     dw      00014h  ; turn off dword mode
  23.     dw      0e317h  ; turn on byte mode
  24.     dw      320     ; width
  25.     dw      200     ; height
  26.  
  27. LABEL X320Y200s word
  28.     db      0e3h    ; dot clock
  29.     db      02      ; Number of CRTC Registers to update
  30.     dw      00014h  ; turn off dword mode
  31.     dw      0e317h  ; turn on byte mode
  32.     dw      320     ; width
  33.     dw      200     ; height
  34.  
  35. LABEL X320Y240 word
  36.     db      0e3h    ; dot clock
  37.     db      10      ; Number of CRTC Registers to update
  38.     dw      00d06h  ; vertical total
  39.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  40.     dw      04109h  ; cell height (2 to double-scan)
  41.     dw      0ea10h  ; v sync start
  42.     dw      0ac11h  ; v sync end and protect cr0-cr7
  43.     dw      0df12h  ; vertical displayed
  44.     dw      00014h  ; turn off dword mode
  45.     dw      0e715h  ; v blank start
  46.     dw      00616h  ; v blank end
  47.     dw      0e317h  ; turn on byte mode
  48.     dw      320     ; width
  49.     dw      240     ; height
  50.  
  51. LABEL X360Y200 word
  52.     db      0e7h    ; dot clock
  53.     db      08      ; Number of CRTC Registers to update
  54.     dw      06b00h  ; horz total
  55.     dw      05901h  ; horz displayed
  56.     dw      05a02h  ; start horz blanking
  57.     dw      08e03h  ; end horz blanking
  58.     dw      05e04h  ; start h sync
  59.     dw      08a05h  ; end h sync
  60.     dw      00014h  ; turn off dword mode
  61.     dw      0e317h  ; turn on byte mode
  62.     dw      360     ; width
  63.     dw      200     ; height
  64.  
  65. LABEL X360Y240 word
  66.     db      0e7h    ; dot clock
  67.     db      16      ; Number of CRTC Registers to update
  68.     dw      06b00h  ; horz total
  69.     dw      05901h  ; horz displayed
  70.     dw      05a02h  ; start horz blanking
  71.     dw      08e03h  ; end horz blanking
  72.     dw      05e04h  ; start h sync
  73.     dw      08a05h  ; end h sync
  74.     dw      00d06h  ; vertical total
  75.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  76.     dw      04109h  ; cell height (2 to double-scan)
  77.     dw      0ea10h  ; v sync start
  78.     dw      0ac11h  ; v sync end and protect cr0-cr7
  79.     dw      0df12h  ; vertical displayed
  80.     dw      00014h  ; turn off dword mode
  81.     dw      0e715h  ; v blank start
  82.     dw      00616h  ; v blank end
  83.     dw      0e317h  ; turn on byte mode
  84.     dw      360
  85.     dw      240
  86.  
  87. LABEL X376Y282 word
  88.     db      0e7h
  89.     db      18
  90.     dw      06e00h  ; horz total
  91.     dw      05d01h  ; horz displayed
  92.     dw      05e02h  ; start horz blanking
  93.     dw      09103h  ; end horz blanking
  94.     dw      06204h  ; start h sync
  95.     dw      08f05h  ; end h sync
  96.     dw      06206h  ; vertical total
  97.     dw      0f007h  ; overflow
  98.     dw      06109h  ; cell height
  99.     dw      0310fh  ;
  100.     dw      03710h  ; v sync start
  101.     dw      08911h  ; v sync end and protect cr0-cr7
  102.     dw      03312h  ; vertical displayed
  103.     dw      02f13h  ; offset
  104.     dw      00014h  ; turn off dword mode
  105.     dw      03c15h  ; v blank start
  106.     dw      05c16h  ; v blank end
  107.     dw      0e317h  ; turn on byte mode
  108.     dw      376
  109.     dw      564         ;Jeff asks if this should be 282
  110.  
  111. LABEL X320Y400 word
  112.     db      00      ;0e3h    ; dot clock
  113.     db      03      ; Number of CRTC Registers to update
  114.     dw      04009h  ; cell height
  115.     dw      00014h  ; turn off dword mode
  116.     dw      0e317h  ; turn on byte mode
  117.     dw      320     ; width
  118.     dw      400     ; height
  119.  
  120. LABEL X320Y480 word
  121.     db      0e3h    ; dotclock
  122.     db      10      ; Number of CRTC Registers to update
  123.     dw      00d06h  ; vertical total
  124.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  125.     dw      04009h  ; cell height (2 to double-scan)
  126.     dw      0ea10h  ; v sync start
  127.     dw      0ac11h  ; v sync end and protect cr0-cr7
  128.     dw      0df12h  ; vertical displayed
  129.     dw      00014h  ; turn off dword mode
  130.     dw      0e715h  ; v blank start
  131.     dw      00616h  ; v blank end
  132.     dw      0e317h  ; turn on byte mode
  133.     dw      320     ; width
  134.     dw      480     ; height
  135.  
  136. LABEL X360Y400 word
  137.     db      0e7h    ; dot clock
  138.     db      09      ; Number of CRTC Registers to update
  139.     dw      06b00h  ; horz total
  140.     dw      05901h  ; horz displayed
  141.     dw      05a02h  ; start horz blanking
  142.     dw      08e03h  ; end horz blanking
  143.     dw      05e04h  ; start h sync
  144.     dw      08a05h  ; end h sync
  145.     dw      04009h  ; cell height
  146.     dw      00014h  ; turn off dword mode
  147.     dw      0e317h  ; turn on byte mode
  148.     dw      360     ; width
  149.     dw      400     ; height
  150.  
  151.  
  152. LABEL X360Y480 word
  153.     db      0e7h
  154.     db      17
  155.     dw      06b00h  ; horz total
  156.     dw      05901h  ; horz displayed
  157.     dw      05a02h  ; start horz blanking
  158.     dw      08e03h  ; end horz blanking
  159.     dw      05e04h  ; start h sync
  160.     dw      08a05h  ; end h sync
  161.     dw      00d06h  ; vertical total
  162.     dw      03e07h  ; overflow
  163.     dw      04009h  ; cell height
  164.     dw      0ea10h  ; v sync start
  165.     dw      0ac11h  ; v sync end and protect cr0-cr7
  166.     dw      0df12h  ; vertical displayed
  167.     dw      02d13h  ; offset
  168.     dw      00014h  ; turn off dword mode
  169.     dw      0e715h  ; v blank start
  170.     dw      00616h  ; v blank end
  171.     dw      0e317h  ; turn on byte mode
  172.     dw      360
  173.     dw      480
  174.  
  175. LABEL X360Y360 word
  176.     db      0e7h
  177.     db      15
  178.     dw      06b00h  ; horz total
  179.     dw      05901h  ; horz displayed
  180.     dw      05a02h  ; start horz blanking
  181.     dw      08e03h  ; end horz blanking
  182.     dw      05e04h  ; start h sync
  183.     dw      08a05h  ; end h sync
  184.     dw      04009h  ; cell height
  185.     dw      08810h  ; v sync start
  186.     dw      08511h  ; v sync end and protect cr0-cr7
  187.     dw      06712h  ; vertical displayed
  188.     dw      02d13h  ; offset
  189.     dw      00014h  ; turn off dword mode
  190.     dw      06d15h  ; v blank start
  191.     dw      0ba16h  ; v blank end
  192.     dw      0e317h  ; turn on byte mode
  193.     dw      360
  194.     dw      360
  195.  
  196. LABEL X376Y308 word
  197.     db      0e7h
  198.     db      18
  199.     dw      06e00h  ; horz total
  200.     dw      05d01h  ; horz displayed
  201.     dw      05e02h  ; start horz blanking
  202.     dw      09103h  ; end horz blanking
  203.     dw      06204h  ; start h sync
  204.     dw      08f05h  ; end h sync
  205.     dw      06206h  ; vertical total
  206.     dw      00f07h  ; overflow
  207.     dw      04009h  ;
  208.     dw      0310fh  ;
  209.     dw      03710h  ; v sync start
  210.     dw      08911h  ; v sync end and protect cr0-cr7
  211.     dw      03312h  ; vertical displayed
  212.     dw      02f13h  ; offset
  213.     dw      00014h  ; turn off dword mode
  214.     dw      03c15h  ; v blank start
  215.     dw      05c16h  ; v blank end
  216.     dw      0e317h  ; turn on byte mode
  217.     dw      376
  218.     dw      308
  219.  
  220. LABEL X376Y564 word
  221.     db      0e7h
  222.     db      18
  223.     dw      06e00h  ; horz total
  224.     dw      05d01h  ; horz displayed
  225.     dw      05e02h  ; start horz blanking
  226.     dw      09103h  ; end horz blanking
  227.     dw      06204h  ; start h sync
  228.     dw      08f05h  ; end h sync
  229.     dw      06206h  ; vertical total
  230.     dw      0f007h  ; overflow
  231.     dw      06009h  ;
  232.     dw      0310fh  ;
  233.     dw      03710h  ; v sync start
  234.     dw      08911h  ; v sync end and protect cr0-cr7
  235.     dw      03312h  ; vertical displayed
  236.     dw      02f13h  ; offset
  237.     dw      00014h  ; turn off dword mode
  238.     dw      03c15h  ; v blank start
  239.     dw      05c16h  ; v blank end
  240.     dw      0e317h  ; turn on byte mode
  241.     dw      376
  242.     dw      564
  243.  
  244. LABEL X256Y240 word
  245.     db      0e3h    ; dot clock
  246.     db      16      ; Number of CRTC Registers to update
  247.  
  248.     dw      05f00h  ; horz total
  249.     dw      03f01h  ; horz displayed
  250.     dw      04002h  ;04202h  ; start horz blanking
  251.     dw      0a003h  ;09f03h  ; end horz blanking
  252.     dw      04f04h  ; start h sync
  253.     dw      00405h  ; end h sync
  254.  
  255.     dw      00d06h  ; vertical total
  256.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  257.     dw      04109h  ; cell height (2 to double-scan)
  258.     dw      0ea10h  ; v sync start
  259.     dw      0ac11h  ; v sync end and protect cr0-cr7
  260.     dw      0df12h  ; vertical displayed
  261.     dw      0e715h  ; v blank start
  262.     dw      00616h  ; v blank end
  263.  
  264.     dw      00014h  ; turn off dword mode
  265.     dw      0e317h  ; turn on byte mode
  266.     dw      256
  267.     dw      240
  268.  
  269. LABEL X256Y70 word
  270.     db      0e3h    ; dot clock
  271.     db      16      ; Number of CRTC Registers to update
  272.  
  273.     dw      05f00h  ; horz total
  274.     dw      03f01h  ; horz displayed
  275.     dw      04002h  ;04202h  ; start horz blanking
  276.     dw      0a003h  ;09f03h  ; end horz blanking
  277.     dw      04f04h  ; start h sync
  278.     dw      00405h  ; end h sync
  279.  
  280.     dw      00d06h  ; vertical total
  281.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  282.     dw      04709h  ; cell height (8 to get blocky)
  283.     dw      0ea10h  ; v sync start
  284.     dw      0ac11h  ; v sync end and protect cr0-cr7
  285.     dw      0df12h  ; vertical displayed
  286.     dw      0e715h  ; v blank start
  287.     dw      00616h  ; v blank end
  288.  
  289.     dw      00014h  ; turn off dword mode
  290.     dw      0e317h  ; turn on byte mode
  291.     dw      256
  292.     dw      240         ;Jeff asks if this should be 70
  293.  
  294. LABEL X256Y154 word
  295.     db      0e3h    ; dot clock
  296.     db      18      ; Number of CRTC Registers to update
  297.  
  298.     dw      05f00h  ; horz total
  299.     dw      03f01h  ; horz displayed
  300.     dw      04002h  ;04202h  ; start horz blanking
  301.     dw      0a003h  ;09f03h  ; end horz blanking
  302.     dw      04f04h  ; start h sync
  303.     dw      00405h  ; end h sync
  304.  
  305.     dw      06206h  ; vertical total
  306.     dw      00f07h  ; overflow
  307.     dw      04109h  ; CELL HEIGHT
  308.     dw      0310fh  ;
  309.     dw      03710h  ; v sync start
  310.     dw      08911h  ; v sync end and protect cr0-cr7
  311.     dw      03312h  ; vertical displayed
  312.     dw      02f13h  ; offset
  313.     dw      00014h  ; turn off dword mode
  314.     dw      03c15h  ; v blank start
  315.     dw      05c16h  ; v blank end
  316.     dw      0e317h  ; turn on byte mode
  317.     dw      256
  318.     dw      308
  319.  
  320. LABEL X256Y282 word
  321.     db      0e3h    ; dot clock
  322.     db      18      ; Number of CRTC Registers to update
  323.  
  324.     dw      05f00h  ; horz total
  325.     dw      03f01h  ; horz displayed
  326.     dw      04002h  ;04202h  ; start horz blanking
  327.     dw      0a003h  ;09f03h  ; end horz blanking
  328.     dw      04f04h  ; start h sync
  329.     dw      00405h  ; end h sync
  330.  
  331.     dw      06206h  ; vertical total
  332.     dw      0f007h  ; overflow
  333.     dw      06109h  ; cell height
  334.     dw      0310fh  ;
  335.     dw      03710h  ; v sync start
  336.     dw      08911h  ; v sync end and protect cr0-cr7
  337.     dw      03312h  ; vertical displayed
  338.     dw      02f13h  ; offset
  339.     dw      00014h  ; turn off dword mode
  340.     dw      03c15h  ; v blank start
  341.     dw      05c16h  ; v blank end
  342.     dw      0e317h  ; turn on byte mode
  343.     dw      256
  344.     dw      564
  345.  
  346.  
  347. LABEL X256Y200 word
  348.     db      0e3h    ; dot clock
  349.     db      8       ; Number of CRTC Registers to update
  350.     dw      05f00h  ; horz total
  351.     dw      03f01h  ; horz displayed
  352.     dw      04002h  ; start horz blanking
  353.     dw      0a003h  ; end horz blanking
  354.     dw      04f04h  ; start h sync
  355.     dw      00405h  ; end h sync
  356.     dw      00014h  ; turn off dword mode
  357.     dw      0e317h  ; turn on byte mode
  358.     dw      256
  359.     dw      200
  360.  
  361. LAST_X_MODE        =     18
  362.  
  363. LABEL ModeTable word    ; Mode X tweak table
  364.     dw      offset X320Y200
  365.     dw      offset X320Y240
  366.     dw      offset X360Y200
  367.     dw      offset X360Y240
  368.     dw      offset X376Y282
  369.     dw      offset X320Y400
  370.     dw      offset X320Y480
  371.     dw      offset X360Y400
  372.     dw      offset X360Y480
  373.     dw      offset X360Y360
  374.     dw      offset X376Y308
  375.     dw      offset X376Y564
  376.     dw      offset X256Y240
  377.     dw      offset X256Y200
  378.     dw      offset X320Y200s
  379.     dw      offset X256Y154
  380.     dw      offset X256Y282
  381.     dw      offset X256Y70
  382.     dw      offset X320Y80
  383.  
  384. M320x200x256 =0     ;constants for easy calling
  385. M320x240x256 =1
  386. M360x200x256 =2
  387. M360x240x256 =3
  388. M376x282x256 =4
  389. M320x400x256 =5
  390. M320x480x256 =6
  391. M360x400x256 =7
  392. M360x480x256 =8
  393. M360x360x256 =9
  394. M376x308x256 =10
  395. M376x564x256 =11
  396. M256x240x256 =12    ;GREAT modes - ypos is upper byte, xpos is lower
  397. M256x200x256 =13
  398. M320x200x256s=14
  399. M256x154x256 =15
  400. M256x282x256 =16
  401. M256x70x256 =17
  402. M320x80x256 =18
  403.  
  404. InputStatus1=   3dah
  405. Misc_Output =   3c2h
  406. SC_Index    =   3c4h
  407. CRTC_Index  =   3d4h
  408. Graph_Index =   3ceh
  409. Attr_Index  =   3c0h    ;don't forget to clear flipflop & set bit 5 on index
  410. PEL_Write   =   3c8h
  411. PEL_Read    =   3c7h
  412. PEL_Data    =   3c9h
  413.  
  414. VGASeg          dw  0A000h      ;VGA refresh buffer segment
  415. ModeXWidth      dw  0           ;physical width of current mode (in pixels)
  416. ModeXHeight     dw  0           ;physical height of current mode (in pixels)
  417. _Scrw           dw  0           ;logical width of current mode (in pixels)
  418. ModeXLogWidth   dw  0           ;logical width of current mode (in bytes)
  419. _Mode           dw  0           ;Mode X video number
  420.  
  421. MACRO @SetModeX DaMode,DaWidth
  422.     mov     ax,DaMode
  423.     mov     cx,DaWidth
  424.     call    _Set_X_Mode
  425. ENDM @SetModeX
  426.  
  427. ;-----------------------------------------------------------------------
  428. ;
  429. ;   Sets mode # in AX, returns ax=0 if successful, ax=-1 if failed
  430. ;   cx= width of screen
  431. ;
  432. ; SetModeX Adapted for VLA by Draeden,
  433. ; Originally written by Themie Gouthas,
  434. ; who adapted parts from M. Abrash code.
  435. ; (Talk about code reuse!)
  436. ;------------------------------------------------------------------------
  437. PROC _Set_X_Mode NEAR
  438.     pusha
  439.     push    es ds
  440.  
  441.     cld
  442.     mov     bx,cs
  443.     mov     ds,bx
  444.     mov     es,bx
  445.  
  446.     cmp     ax,LAST_X_MODE      ; have we selected a valid mode?
  447.     jle     @@ValidMode         ; Yes !
  448.  
  449.     pop     ds es
  450.     popa
  451.     mov     ax,-1               ; idiot.
  452.     ret
  453.  
  454. @@ValidMode:
  455.     mov     [_Mode],ax
  456.     mov     [_Scrw],cx
  457.  
  458.     mov     ax,13h              ; let the BIOS set standard 256-color
  459.     int     10h                 ;  mode (320x200 linear)
  460.  
  461.     mov     dx,SC_Index
  462.     mov     ax,0604h
  463.     out     dx,ax               ; disable chain4 mode
  464.     mov     ax,0100h
  465.     out     dx,ax               ; synchronous reset while setting Misc
  466.                                 ;  Output for safety, even though clock
  467.                                 ;  unchanged
  468.     mov     bx,[_Mode]
  469.     add     bx,bx
  470.     mov     si,[bx + ModeTable]
  471.     lodsb
  472.  
  473.     or      al,al
  474.     jz      @@DontSetDot
  475.     mov     dx,Misc_Output
  476.     out     dx,al               ; select the dot clock and Horiz
  477.                                 ;  scanning rate
  478. @@DontSetDot:
  479.     mov     dx,SC_Index
  480.     mov     ax,0300h
  481.     out     dx,ax               ; undo reset (restart sequencer)
  482.  
  483.     mov     dx,CRTC_Index       ; reprogram the CRT Controller
  484.     mov     al,11h              ; VSync End reg contains register write
  485.     out     dx,al               ; protect bit
  486.     inc     dx                  ; CRT Controller Data register
  487.     in      al,dx               ; get current VSync End register setting
  488.     and     al,07fh             ; remove write protect on various
  489.     out     dx,al               ; CRTC registers
  490.     dec     dx                  ; CRT Controller Index
  491.     xor     cx,cx
  492.     lodsb
  493.     mov     cl,al
  494.  
  495. @@SetCRTParmsLoop:
  496.     lodsw                       ; get the next CRT Index/Data pair
  497.     out     dx,ax               ; set the next CRT Index/Data pair
  498.     dec     cx
  499.     jne     @@SetCRTParmsLoop
  500.  
  501.     lodsw
  502.     mov     [cs:ModeXWidth],ax
  503.     lodsw
  504.     mov     [cs:ModeXHeight],ax
  505.  
  506.     mov     dx,SC_Index
  507.     mov     ax,0f02h
  508.     out     dx,ax               ; enable writes to all four planes
  509.  
  510.                                 ; now clear all display memory, 8 pixels
  511.     mov     es,[cs:VGASeg]      ; at a time
  512.     sub     di,di               ; point ES:DI to display memory
  513.     sub     ax,ax               ; clear to zero-value pixels
  514.     mov     cx,8000h            ; # of words in display memory
  515.     rep     stosw               ; clear all of display memory
  516.  
  517.     ;  Mode X is set, now set the required logical page width.
  518.  
  519.     mov     cx,[cs:_Scrw]
  520.     shr     cx,2
  521.     mov     [cs:ModeXLogWidth],cx
  522.     shr     cx,1            ;divide by 8
  523.     mov     dx,CRTC_Index
  524.     mov     al,13h
  525.     mov     ah,cl
  526.     out     dx,ax
  527.  
  528.     pop     ds es
  529.     popa
  530.     xor     ax,ax
  531.     ret
  532. ENDP _Set_X_Mode
  533.  
  534. ────────────────────────────────────────────────────────────────────────────
  535. ;*   MISC planar mode routines
  536. ────────────────────────────────────────────────────────────────────────────
  537.  
  538.     ;ah: 0000b : bit 0= plane 0, bit 1=plane 1, etc..
  539.     ;
  540.     ;DESTROYS: al, dx
  541.     ;
  542. MACRO  @Set_Write_Plane
  543.     mov     dx,SC_Index
  544.     mov     al,2
  545.     and     ah,1111b
  546.     out     dx,ax
  547. ENDM   @Set_Write_Plane
  548.  
  549.     ;ah: plane to latch for read (0-3)
  550.     ;
  551.     ;DESTROYS: al, dx
  552.     ;
  553. MACRO  @Set_Read_Plane
  554.     mov     dx,Graph_Index
  555.     mov     al,4
  556.     out     dx,ax
  557. ENDM   @Set_Read_Plane
  558.  
  559.     ;ah: write mode (0-3)
  560.     ;
  561.     ;DESTROYS: ax, dx
  562.     ;
  563. MACRO @Set_Write_Mode
  564.     mov     dx,Graph_Index
  565.     mov     al,5
  566.     out     dx,al
  567.     inc     dx
  568.     in      al,dx
  569.     and     al,11111100b    ;clear out write mode bits
  570.     and     ah,00000011b
  571.     or      al,ah
  572.     out     dx,al
  573. ENDM  @Set_Write_Mode
  574.  
  575.     ;ah: Read mode (0-1)
  576.     ;
  577.     ;DESTROYS: ax, dx
  578.     ;
  579. MACRO @Set_Read_Mode
  580.     mov     dx,Graph_Index
  581.     mov     al,5
  582.     out     dx,al
  583.     inc     dx
  584.     in      al,dx
  585.     and     al,11110111b    ;clear out write mode bits
  586.     shl     ah,3            ;move bit to correct position
  587.     and     ah,00001000b
  588.     or      al,ah
  589.     out     dx,al
  590. ENDM  @Set_Read_Mode
  591.  
  592.     ;bx: starting offset
  593.     ;
  594.     ;DESTROYS: ax, dx
  595.     ;
  596. MACRO @Set_Start_Offset
  597.     mov     dx,CRTC_Index
  598.     mov     al,0ch
  599.     mov     ah,bh       ;write the HIGH byte
  600.     out     dx,ax
  601.     inc     al
  602.     mov     ah,bl       ;write the LOW byte
  603.     out     dx,ax
  604. ENDM  @Set_Start_Offset
  605.  
  606.     ;ah = pelpan value
  607.     ;
  608.     ;DESTROYS: ax, dx
  609.     ;
  610. MACRO @Set_HPP
  611.     mov     dx,InputStatus1
  612.     in      al,dx           ;dummy input
  613.     mov     dx,Attr_Index
  614.     mov     al,33h
  615.     out     dx,al
  616.     mov     al,ah
  617.     out     dx,al
  618. ENDM
  619.  
  620.     ;DESTROYS: ax, dx   - sets pixel pan compatibility
  621.     ;
  622. MACRO @Set_PPC
  623.     mov     dx,InputStatus1
  624.     in      al,dx           ;dummy input
  625.     mov     dx,Attr_Index
  626.     mov     al,30h
  627.     out     dx,al
  628.     inc     dx
  629.     in      al,dx
  630.     dec     dx
  631.     or      al,00100000b
  632.     out     dx,al
  633. ENDM
  634.  
  635.     ;bx: scanline to set split screen at
  636.     ;
  637.     ;DESTROYS: ax, dx
  638.     ;
  639. MACRO @Set_Split
  640.     mov     al,18h
  641.     mov     ah,bl
  642.     mov     dx,CRTC_Index
  643.     out     dx,ax       ;set bits 0-7
  644.  
  645.     mov     al,09h
  646.     out     dx,al
  647.     inc     dx
  648.     in      al,dx
  649.     mov     ah,bh
  650.     and     ah,00000010b
  651.     shl     ah,5
  652.     and     al,10111111b
  653.     or      al,ah
  654.     out     dx,al       ;set bit 9
  655.  
  656.     dec     dx
  657.     mov     al,07h
  658.     out     dx,al
  659.     inc     dx
  660.     in      al,dx
  661.     and     al,11101111b
  662.     mov     ah,bh
  663.     and     ah,00000001b
  664.     shl     ah,4
  665.     or      al,ah
  666.     out     dx,al       ;set bit 8
  667. ENDM @Set_Split
  668.  
  669. MACRO @FullVertWait
  670.  LOCAL @@VR, @@NVR
  671.     mov     dx,InputStatus1
  672. @@VR:
  673.     in      al,dx
  674.     test    al,8
  675.     jz      @@VR                    ;wait until Verticle Retrace starts
  676. @@NVR:
  677.     in      al,dx
  678.     test    al,8
  679.     jnz     @@NVR                   ;wait until Verticle Retrace Ends
  680. ENDM @FullVertWait
  681.  
  682. MACRO @WaitVert
  683.  LOCAL @@VR
  684.     mov     dx,InputStatus1
  685. @@VR:
  686.     in      al,dx
  687.     test    al,8
  688.     jz      @@VR                    ;wait until Verticle Retrace starts
  689. ENDM  @WaitVert
  690.  
  691. MACRO @WaitVertEnd
  692.   LOCAL @@NVR
  693.     mov     dx,InputStatus1
  694. @@NVR:
  695.     in      al,dx
  696.     test    al,8
  697.     jnz     @@NVR                   ;wait until Verticle Retrace Ends
  698. ENDM  @WaitVertEnd
  699.  
  700.     ;si = offset to palette
  701.     ;cx = number of colors to write
  702.     ;al = starting palette register
  703.     ;
  704.     ;DESTROYS: dx,si,cx
  705.     ;
  706. MACRO @WritePalette
  707.     mov     dx,cx
  708.     add     cx,cx
  709.     add     cx,dx
  710.     mov     dx,03c8h
  711.     out     dx,al
  712.     inc     dx
  713.     cld
  714.     rep outsb
  715. ENDM @WritePalette
  716.  
  717.     ;Changes the mode back to ModeX after a ResetLinear was called
  718. MACRO @ResetModeX
  719.     mov     dx,SC_Index
  720.     mov     ax,0604h
  721.     out     dx,ax               ; disable chain4 mode
  722.  
  723.     mov     dx,CRTC_Index
  724.     mov     ax,00014h           ; turn off dword mode
  725.     out     dx,ax
  726.     mov     ax,0e317h           ; turn on byte mode
  727.     out     dx,ax
  728. ENDM
  729.  
  730.     ;changes from ModeX to normal linear mode
  731.     ; only will work with an 320x200 screen w/ screenwidth of 80 bytes
  732. MACRO @ResetLinear
  733.     mov     dx,SC_Index
  734.     mov     ax,0E04h
  735.     out     dx,ax               ; enable chain4 mode
  736.  
  737.     mov     dx,CRTC_Index       ; reprogram the CRT Controller
  738.     mov     ax,04014h           ; turn on dword mode
  739.     out     dx,ax
  740.     mov     ax,0a317h           ; turn off byte mode
  741.     out     dx,ax
  742. ENDM
  743.